package com.hr.system.controller;

import java.util.List;

import com.hr.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hr.common.annotation.Log;
import com.hr.common.enums.BusinessType;
import com.hr.system.domain.SysDeduction;
import com.hr.system.service.ISysDeductionService;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.utils.poi.ExcelUtil;
import com.hr.common.core.page.TableDataInfo;

/**
 * 员工工资扣除项Controller
 * 
 * @author ruoyi
 * @date 2021-04-29
 */
@Controller
@RequestMapping("/system/deduction")
public class SysDeductionController extends BaseController
{
    private String prefix = "system/deduction";

    @Autowired
    private ISysDeductionService sysDeductionService;

    @RequiresPermissions("system:deduction:view")
    @GetMapping()
    public String deduction()
    {
        return prefix + "/deduction";
    }

    /**
     * 查询员工工资扣除项列表
     */
    @RequiresPermissions("system:deduction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysDeduction sysDeduction)
    {
        startPage();
        sysDeduction.setTenantId(Integer.toUnsignedLong(ShiroUtils.getTenantId()));
        List<SysDeduction> list = sysDeductionService.selectSysDeductionList(sysDeduction);
        return getDataTable(list);
    }

    /**
     * 导出员工工资扣除项列表
     */
    @RequiresPermissions("system:deduction:export")
    @Log(title = "员工工资扣除项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysDeduction sysDeduction)
    {
        List<SysDeduction> list = sysDeductionService.selectSysDeductionList(sysDeduction);
        ExcelUtil<SysDeduction> util = new ExcelUtil<SysDeduction>(SysDeduction.class);
        return util.exportExcel(list, "deduction");
    }

    /**
     * 新增员工工资扣除项
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工工资扣除项
     */
    @RequiresPermissions("system:deduction:add")
    @Log(title = "员工工资扣除项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysDeduction sysDeduction)
    {
        return toAjax(sysDeductionService.insertSysDeduction(sysDeduction));
    }

    /**
     * 修改员工工资扣除项
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysDeduction sysDeduction = sysDeductionService.selectSysDeductionById(id);
        mmap.put("sysDeduction", sysDeduction);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工工资扣除项
     */
    @RequiresPermissions("system:deduction:edit")
    @Log(title = "员工工资扣除项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysDeduction sysDeduction)
    {
        return toAjax(sysDeductionService.updateSysDeduction(sysDeduction));
    }

    /**
     * 删除员工工资扣除项
     */
    @RequiresPermissions("system:deduction:remove")
    @Log(title = "员工工资扣除项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysDeductionService.deleteSysDeductionByIds(ids));
    }
}
